package com.itheima.discuss.controller;

import com.itheima.discuss.entity.DiscussEntity;
import com.itheima.discuss.service.DiscussService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/discuss")
public class DiscussController {

    @Autowired
    private DiscussService discussService;

    //添加评论
    @PostMapping("/addDiscuss")
    public String addDiscuss(@RequestBody DiscussEntity discussEntity){

        discussService.addDiscuss(discussEntity);
        return "success";
    }

    //查看评论
    @GetMapping("/getDiscuss/{articleId}")
    public List<DiscussEntity> getDiscuss(@PathVariable("articleId") String articleId){
        return discussService.getDiscuss(articleId);
    }

    //对某条评论追加回复
    @PostMapping("/addReply/{discussId}")
    public String addReply(@PathVariable("discussId")String discussId,@RequestBody DiscussEntity discussEntity){
        discussService.addReply(discussId,discussEntity);
        return "success";
    }

    //给评论点赞(更新LikeNums)
    @PostMapping("/incrLikeNums/{discussId}")
    public String incrLikeNums(@PathVariable("discussId") String discussId){
        discussService.incrLikeNums(discussId);
        return "success";
    }

    //按id统计文章评论量
    @GetMapping("/getTotalCommentNum/{articleId}")
    public Long getTotalCommentNum(@PathVariable("articleId") String articleId){
        return discussService.getTotalCommentNum(articleId);
    }

    //根据文章分组，并统计每个文章的总点赞数
    @GetMapping("/getArticleLikeNums")
    public List<Map> getArticleLikeNums(){
        return discussService.getArticleLikeNums();
    }

    //按文章分组，获取点赞数最多的文章
    @GetMapping("/getMaxLikeNumsArticle")
    public Map getMaxLikeNumsArticle(){
        return discussService.getMaxLikeNumsArticle();
    }

}
